n = int(input())
res = []
for _ in range(n):
    l = int(input())
    line = list(map(int, input().split()))
    line.sort()
    count = 0
    for i in range(l-2):
        if line[i] == 0:
            continue
        r = i + 2
        for j in range(i+1, l-1):
            while r < len(line) and line[r] < (line[i] + line[j]):
                r += 1
            count += r - j - 1
    res.append(count)
for x in res:
    print(x)